const path = require('path');
const HTMLPlugin = require('html-webpack-plugin');
const webpack = require('webpack');

module.exports = {
    entry:{
        index:'./src/js/index.js'
    },
    output:{
        path:path.resolve(__dirname,'../dist'),
        filename:'./js/[name].[hash].js'
    },
    module:{
        rules:[
            {
                test:/\.js$/,
                use:{
                    loader:'babel-loader'
                }
            },
            {
                test:/\.(jpg|png|gif)/,
                use:{
                    loader:'url-loader',
                    options:{
                        limit:1024,
                        name:'./img/[name].[ext]',
                        publicPahtn:'/'
                    }
                }
            },
            {
                test:/\.html$/,
                use:{
                    loader:'html-loader',
                    options:{
                        attrs:[':src']
                    }
                }
            }
        ]
    },
    plugins:[
        new HTMLPlugin({
            template:'./src/index.html',
            inject:true,
            filename:'index.html',
            title:'首页'
        }),
        new webpack.HotModuleReplacementPlugin()
    ],
    resolve:{
        alias:{
            'css':path.resolve(__dirname,'../src/scss')
        },
        extensions:['.js','.scss']
    }
}
